//Membres > middle
jQuery(function($){
  jQuery('.accordion').accordion({
     autoHeight: false
    ,collapsible: false
  });
  var $option = jQuery('button.classement').button({
    text: true,
    icons: {
       primary: "ui-icon-gear"
      ,secondary: "ui-icon-triangle-1-s"
    }  
  }).effect('pulsate');
  
  $option.bind("click mouseenter",function(event){
    var menu = $( this ).next().show().position({
        my: "right top",
        at: "right bottom",
        of: this
    }).menu();
    $(document).one("click", function(e) {
        menu.hide();
    }).one("keyup",function(e){
        menu.hide();
    });
    return com.lolita.utils.cancelEvent(event);
  }).next().menu().hide();
  
  var switchVision = function($obj){
    var to = $obj.attr('href').split('#')[1] || 0;
    $option.next().find('.ui-icon-check').prependTo($obj.parent());
    var $visible = jQuery('.accordion .line:visible');
    if($visible.is(':not('+to+')')){
      $visible.slideUp();
      jQuery('.accordion '+to).slideDown();
    }
    jQuery('.warn-classement').hide();
  }
  
  jQuery('button.classement').next().children(':first-child').children('a').click(function(event){
    switchVision(jQuery(this));
    //return com.lolita.utils.cancelEvent(event); 
  }).end().next().find('a').click(function(event){
    switchVision(jQuery(this));
    //return com.lolita.utils.cancelEvent(event); 
  });
  
  com.lolita.display.makeTeamPick('#combo-equipe',null,{
      callback : {
        onSelect: function(rep,ui){
          if(rep && rep.item && rep.item.value){
            com.lolita.dialog.team(rep.item.value);
          }
        }
      }
    });  
  com.lolita.display.makeMemberPick('#combo-membre',null,{
      callback : {
        onSelect: function(rep,ui){
          if(rep && rep.item && rep.item.value){
            com.lolita.dialog.player(rep.item.value);
          }
        }
      }
    });
  
});
